<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Nested grids demo</title>

  <link rel="stylesheet" href="demo.css"/>

  <script src="../src/jquery.js"></script>
  <script src="../src/gridstack.js"></script>
  <script src="../src/jquery-ui.js"></script>
  <script src="../src/gridstack.jQueryUI.js"></script>

  <style type="text/css">
    .grid-stack .grid-stack {
      /*margin: 0 -10px;*/
      background: rgba(255, 255, 255, 0.3);
    }
    .grid-stack .grid-stack .grid-stack-item-content {
      background: lightpink;
    }
  </style>
</head>
<body>
  <div class="container-fluid">
    <h1>Nested grids demo</h1>
    <a class="btn btn-primary" onClick="addNewWidget(grid1)" href="#">Add Widget Grid1</a>
    <a class="btn btn-primary" onClick="addNewWidget(grid2)" href="#">Add Widget Grid2</a>
    <br><br>

    <div class="grid-stack top">
      <div class="grid-stack-item" data-gs-x="0" data-gs-y="0" data-gs-width="1" data-gs-height="1">
        <div class="grid-stack-item-content">regular item</div>
      </div>
      <div class="grid-stack-item" data-gs-x="1" data-gs-y="0" data-gs-width="4" data-gs-height="4">
        <div class="grid-stack-item-content">
          nested 1 - can drag items out
          <div class="grid-stack nested1">
            <div class="grid-stack-item sub" data-gs-x="0" data-gs-y="0" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">1</div></div>
            <div class="grid-stack-item sub" data-gs-x="3" data-gs-y="0" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">2</div></div>
            <div class="grid-stack-item sub" data-gs-x="6" data-gs-y="0" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">3</div></div>
            <div class="grid-stack-item sub" data-gs-x="9" data-gs-y="0" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">4</div></div>
            <div class="grid-stack-item sub" data-gs-x="0" data-gs-y="1" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">5</div></div>
            <div class="grid-stack-item sub" data-gs-x="3" data-gs-y="1" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">6</div></div>
          </div>
        </div>
    </div>
    <div class="grid-stack-item" data-gs-x="5" data-gs-y="0" data-gs-width="3" data-gs-height="4">
      <div class="grid-stack-item-content">
        nested 2 - constrained to parent (default)
        <div class="grid-stack nested2">
          <div class="grid-stack-item sub" data-gs-x="0" data-gs-y="0" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">7</div></div>
          <div class="grid-stack-item sub" data-gs-x="0" data-gs-y="3" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">8</div></div>
        </div>
      </div>
    </div>
  </div>

  <script type="text/javascript">
    var nestOptions = {
      acceptWidgets: '.grid-stack-item.sub', // only pink sub items can be inserted, otherwise grid-items causes all sort of issues
      dragOut: true // let us drag them out!
    };
    GridStack.init(null, '.grid-stack.top');
    var grid1 = GridStack.init(nestOptions, '.grid-stack.nested1');
    nestOptions.dragOut = false;
    var grid2 = GridStack.init(nestOptions, '.grid-stack.nested2');

    var count = 9;
    addNewWidget = function(grid) {
      var node = {
        x: Math.round(12 * Math.random()),
        y: Math.round(5 * Math.random()),
        width: Math.round(1 + 3 * Math.random()),
        height: Math.round(1 + 3 * Math.random())
      };
      grid.addWidget('<div class="grid-stack-item sub"><div class="grid-stack-item-content">' + count++ + '</div></div>', node);
      return false;
    };
  </script>
</body>
</html>
